<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Goods extends Model
{
    /**
     * 定义主键字段
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 定义表名，不含前缀
     *
     * @var string
     */
    protected $table      = 'wd_goods';

    /**
     * 定义拒绝保存的字段
     *
     * @var array
     */
    protected $guarded    = ['id'];

    /**
     * 开启laravel默认的时间记录
     *
     * @var bool
     */
    public $timestamps = true;

    public function getPicAttribute( $value )
    {
        return json_decode( $value, true );
    }

    /**
     * 管理规格表
     *
     * @return void
     */
    public function norm()
    {
        return $this->hasMany('App\Models\GoodsNorm', 'goods_id', 'id');
    }

    /**
     * 关联商品品牌表
     * @return [type] [description]
     */
    public function brand()
    {
        return $this->belongsTo('App\Models\GoodsBrand', 'goods_brand_id', 'id');
    }

    public function supplier()
    {
        return $this->belongsTo('App\Models\Supplier', 'supplier_id', 'id');
    }
}
